package com.dragon.mmochat.message;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.MmochatMain;
import com.dragon.mmochat.model.enumType.MmochatServerType;
import com.dragon.mmochat.model.map.MmochatMovePoint;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_2_2S extends SkymobiProtocolMessage {
	int mapId;
	byte line;
	MmochatPlayer me;
	List<MmochatMovePoint> moves = new ArrayList<MmochatMovePoint>();

	public Mmochat_2_2S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_2_2);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		out.putInt(mapId);
		out.put(line);
		out.put((byte) moves.size());
		for (MmochatMovePoint move : moves) {
			if (MmochatMain.serverType == MmochatServerType.跨服战服务器
					&& move.getPlayer().getRoleId() == me.getRoleId()) {
				out.putInt(MmochatPlayer.getRealRoleId(move.getPlayer()
						.getRoleId()));
			} else {
				out.putInt(move.getPlayer().getRoleId());
			}
			out.put((byte) move.getPlayer().getRoleType().getValue());
			out.putUnsignedInt(move.getPlayer().getStateValue(me));
			out.put((byte) move.getPreStep());
			out.putShort(move.getX());
			out.putShort(move.getY());
		}
	}

	public void setMapId(int mapId) {
		this.mapId = mapId;
	}

	public void setLine(byte line) {
		this.line = line;
	}

	public void setMoves(List<MmochatMovePoint> moves) {
		this.moves = new ArrayList<MmochatMovePoint>(moves);
	}

	public void setMe(MmochatPlayer me) {
		this.me = me;
	}

}